//The purpose of dynamic_cast is to deal with the case in which
//the correctness of the conversion cannot be determined by the compiler

//dynamic cast of pointer
//For a pointer p, dynamic_cast<T*>(p) can be seen as the question:
//"Is the object pointed to by p of type T?"
 
#include <iostream>
using namespace std;

class A {
  int aa;
};

class B : public A{
  int bb;
};

class C{
  int cc;
};

int main()
{
  B b;
  A* ap;
  C* cp;
  ap = dynamic_cast<A*>(&b);
  if(ap  ){ //if b error: cannot dynamic_cast B b to A*
    cout<<"B b is a type of A"<<endl;
  }
  else {
    cout<<"B b is not a type of A"<<endl;
  }
  cout<<"------------------------"<<endl;
 //  if(cp = dynamic_cast<C*>(&b) ){//error(cannot(source typeis not polymorphic))
//     cout<<"B b is a type of C"<<endl;
//   }
//   else {
//     cout<<"B b is not a type of C"<<endl;
//   }

  return 0;
}
